<?
	if(isset($_GET['keyword']) && ($_GET['keyword'] != "")){
		$keyword = $_GET['keyword'];
		$kw = " AND (t_tieude like '%".$keyword."%' OR t_mota like '%".$keyword."%' OR t_chitiet like '%".$keyword."%') ";
	}else{
		$kw = "";
	}
	
	if(isset($_GET['ttid']) && ($_GET['ttid'] != "") ){$ttid = intval($_GET['ttid']);}
	

	$sql = "SELECT * FROM ".$prefix."sanpham WHERE 1 ".$kw."";
	
	/////////TIM KIEM THEO TINH THANH ///////////
	if(isset($ttid) && ($ttid != "") ){
		$sql .= " AND t_tinhthanh = '".$ttid."'";
	}
	/////TIM KIEM THEO GIA
	if(isset($_GET['act']) && ($_GET['act'] == 'theogia')){
		if(isset($_GET['fgid']) && ($_GET['fgid'] != "") ){$fgid = $_GET['fgid'];}else{reHome($urlHome);}
		if(isset($_GET['tgid']) && ($_GET['tgid'] != "") ){$tgid = $_GET['tgid'];}else{reHome($urlHome);}
		//
		if($fgid == 0){
			$sql .= " AND t_giaban >= 0 AND t_giaban <= ".$tgid."";
		}else if($tgid == 0){
			$sql .= " AND t_giaban >= ".$tgid."";
		}else{
			$sql .= " AND t_giaban >= ".$fgid." AND t_giaban <= ".$tgid."";
		}
	}

	/////////////////////
	if(isset($_GET['sid'])){$sid = intval($_GET['sid']);}
	
	if(isset($sid) && ($sid != "")){
		if($sid == 0){
			$sql = $sql;
		}else if($sid == 1){
			$sql .= " ORDER BY t_id DESC";
		}else if($sid == 2){
			$sql .= " ORDER BY t_id ASC";
		}else if($sid == 3){
			$sql .= " ORDER BY t_giaban ASC";
		}else{
			$sql .= " ORDER BY t_giaban DESC";
		}
	}
	//Paging
	
	$pp=13; 
	$parr=array();
	$parr=paging($sql,$pp);
	$page=$parr[0];
	$limitvalue=$parr[1];
	$numofpages=$parr[2];
	$sql.=" LIMIT $limitvalue, $pp";
	//
	$rss = $db->query($sql);
	
?>
<div id="linkPath">
<div class="linkPath">
    <div class="corner-round-01-top-right">
        <div class="corner-round-01-top-left">
            <div class="corner-round-01-top-bg"></div>
        </div>
    </div>
    <div class="corner-round-01-body">    
        <span style="float: left;"><a href="<?=$root?>/trang-chu/">Trang chủ</a> &raquo; Tìm kiếm</span>
        <span style="float: right;"><a title="Quay lại trang trước" class="link-back" href="javascript:void(0);" onclick="javascript:history.go(-1);">Quay lại</a></span>
        <div style="clear: both;"></div>
    </div>
    <div class="corner-round-01-bottom-right">
        <div class="corner-round-01-bottom-left">
            <div class="corner-round-01-bottom-bg"></div>
        </div>
    </div>   
</div>    
    </div>
    <!-- Main Page-Content { -->    
    <div id="page-content">   
         <div id="page-content-lpane">                                           
            

<!-- Menu Left { -->
	<?
		file_exist('includes/timkiem/inc_menu_left.php');
		include('includes/timkiem/inc_menu_left.php');
	?>
<!-- } Menu Left -->

 
<!-- TU KHOA -->            
<div id="tagMenu" style="width:248px;margin-bottom:5px;">
    <div class="corner-round-05-top-right">
        <div class="corner-round-05-top-left">
            <div class="corner-round-05-top-bg"></div>

        </div>
    </div>
    <div class="corner-round-05-body">        
        <div id="tag-cloud" style="padding-top:5px;">
            <div class="title">Tìm với từ khóa</div>
            <div class="sep"></div>
            <div class="tags">
			
			<?
				$rs = $db->query("SELECT * FROM ".$prefix."tukhoa LIMIT 20");
				$st = 0;
				while($row = $db->fetch_array($rs)){
				$st++;
				$tk_tukhoa = $myString->unQuote(stripslashes($row[tk_tukhoa]));
			?>
				<a style="line-height: 22px;" href="<?=$root?>/tim-kiem/<?=$tk_tukhoa?>"><?=$tk_tukhoa?></a><? if($st != $db->num_rows($rs)){echo ",";} ?>
				
			<?
				
				}
			?>
			
			
			</div>

        </div>
        <div style="height:5px"></div>        
    </div>
    <div class="corner-round-05-bottom-right">
        <div class="corner-round-05-bottom-left">
            <div class="corner-round-05-bottom-bg"></div>
        </div>
    </div>
</div>          
 <!-- TU KHOA -->
 
            
<!-- FiltersBox { -->

	<?
		file_exist('includes/timkiem/inc_timkiem.php');
		include('includes/timkiem/inc_timkiem.php');
	?>

<!-- } FiltersBox -->                                                   
        </div>
        <div id="page-content-mpane-all">            
<script language="javascript">
	function funSort(id,p,act,fgid,tgid,ttid,keyword){
		window.location = '<?=$root?>/?mod=timkiem&sid=' + id + '&p=' + p + '&tukhoa=' + tukhoa + '&act=' + act +'&fgid=' + fgid + '&tgid=' + tgid + '&ttid=' + ttid + '&keyword=' + keyword;
		
	}
</script>            
<div id="filtersDescription">
    <div class="corner-round-04-top-right">
        <div class="corner-round-04-top-left">
            <div class="corner-round-04-top-bg"></div>
        </div>
    </div>

    <div class="corner-round-04-body"> 
        
        <ul id="descriptionBar" style="margin:0px;">
            <li style="float:left;margin:0px;line-height:20px;">Tìm thấy <b class="highline"> <?=$db->num_rows($rss)?> </b> sản phẩm</li>
            <li style="float:right;margin:0px;line-height:20px;" id="menuContainer">                   
                Sắp xếp theo:     
				<select name="sort" style="width:120px;" onchange="funSort(this.value,'<?=$p?>','<?=$act?>','<?=$fgid?>','<?=$tgid?>','<?=$ttid?>','<?=$keyword?>');">
			  	<option value="0" <? if($sid == 0){?> selected="selected" <? }?>>-- Tất cả --</option>
				<option value="1" <? if($sid == 1){?> selected="selected" <? }?>>Mới dần</option>
				<option value="2" <? if($sid == 2){?> selected="selected" <? }?>>Cũ dần</option>
				<option value="3" <? if($sid == 3){?> selected="selected" <? }?>>Giá tăng dần</option>
				<option value="4" <? if($sid == 4){?> selected="selected" <? }?>>Giá giảm dần</option>
			  </select>                                           
            </li>                       
        </ul>

        <br class="clearBoth" style="font-size:0pt;"/> 
        <p>
            <p style='padding-top: 5px;'>&raquo; Bạn đang tìm theo:</p><ul style="list-style:none;"><li><b>- Từ khóa:</b> <?=$keyword?></li></ul>
        </p>        
                      
    </div>
    <div class="corner-round-04-bottom-right">
        <div class="corner-round-04-bottom-left">

            <div class="corner-round-04-bottom-bg"></div>
        </div>
    </div>   
</div> 

     
            

<!-- Product List { -->
<div id="product-list">
    <div id="product-list-header">       
        <div class="product-col product-col-name">
            <p>Tên sản phẩm</p>
        </div>

        <div class="product-col product-col-price">
            <p>Giá</p>
        </div>
        <div class="product-col product-col-region">
            <p>Phạm vi bán</p>
        </div>
    </div>
    <div style="clear:both;height:4px;font-size:0pt;"></div>

    <div id="product-list-body">
        <div class="corner-round-05-top-right">
            <div class="corner-round-05-top-left">
                <div class="corner-round-05-top-bg"></div>
            </div>
        </div>
        <div class="corner-round-05-body2"> 
            
                <table width="100%" cellpadding="0" cellspacing="0" id="products-items">
                
                   <?
if($db->num_rows($rss) != 0){
					$i = 0;
				while($row = $db->fetch_array($rss)){
					$i++;
					$t_id = $row[t_id];
					$t_tieude = stripslashes($row[t_tieude]);
					$t_hinhanh = $PathFile . stripslashes($row[t_hinhanh]);
					$t_mota = stripslashes($row[t_mota]);
					if($row[t_giaban] == 0){
						$t_giaban = "Call";
					}else{
						$t_giaban = showprice(stripslashes($row[t_giaban])) ." ". loadLoaiTien($row[t_loaitien]);
					}
					$t_nguoidang = $row[t_nguoidang];
					$t_tinhthanh = layTinhThanh($row[t_tinhthanh]);
					$t_xemgannhat = $row[t_xemgannhat];
					$solanxem = $row[t_solanxem];
					$comment = loadSoComment($t_id);
					
				?>
					<!-- SAN PHAM THU : <?=$i?> -->
                    <tr>
                        <td class="col-picture">
                            <p> 
                                <a title="<?=$t_tieude?>" href="<?=$root?>/chi-tiet-san-pham/<?=$t_id?>" class="tips product-name">
                          <img style="vertical-align:middle" alt="<?=$t_tieude?>" src="<?=$root?>/<?=$t_hinhanh?>" onerror="this.src='<?=$root?>/themes/images/noimg.jpg'"; width="100" height="100" border="0"/>
                                </a>
                            </p> 
                        </td>
                        <td class="col-name">
                            <h1>

                                <a href="<?=$root?>/chi-tiet-san-pham/<?=$t_id?>" class="product-name" title="<?=$t_tieude?>"><?=$t_tieude?></a>
                            </h1> 
                            <p class="truncate" style="text-align:left;">
                                <?=$t_mota?>
                            </p>        
                            <p style="padding-bottom:5px;">                                
                                Shop: <a href="<?=$root?>/thanh-vien/<?=$t_nguoidang?>/<?=tenNguoiDung($t_nguoidang)?>" class="popup-profile"> <?=tenNguoiDung($t_nguoidang)?></a>      
                            </p> 
                            <p style="font-size:8pt;color:Gray;">

                                <?=$t_xemgannhat?> | Xem: <?=$solanxem?> | Comments: <?=$comment?>
                            </p>
                        </td>
                        <td class="col-price">
                            <p>
                                <?=$t_giaban?>                                        
                            </p>
                        </td>
                        <td class="col-region">
                            <p>

                                <a href="javascript:void(0);"><?=$t_tinhthanh?></a>
                            </p>
                        </td>
                    </tr>  
                 <?
				 	if($i != $db->num_rows($rss)){
				 ?>   
                    <tr>
                        <td colspan="4" style="border-bottom:solid 1px #CCCCCC;height:1px;font-size:0pt;"></td>
                    </tr>                       
                 <? } ?>   
                <? } ?> 
	 <? }else{ ?>
 				<tr>
					<td align="left" style="padding-left:10px;">Không tìm thấy kết quả nào !</td>
				</tr>
 	<? } ?>                                 
					
                </table> 
                
        </div>

        <div class="corner-round-05-bottom-right">
            <div class="corner-round-05-bottom-left">
                <div class="corner-round-05-bottom-bg"></div>
            </div>
        </div>    
    </div>
    <div id="product-list-footer"></div>
</div>

<!-- Paging { -->
<div id="paging">

    <div class="corner-round-01-top-right">
        <div class="corner-round-01-top-left">
            <div class="corner-round-01-top-bg"></div>
        </div>
    </div>
    <div class="corner-round-01-body" style="text-align:right;">            
        <!-- paging -->
		 <p align="center" class="font">
	 <?php echo page_div( "".$root."/?mod=timkiem&keyword=".$keyword."&sid=".$sid."&tukhoa=".$tukhoa."&act=".$act."&fgid=".$fgid."&tgid=".$tgid."&ttid=".$ttid."&p=%d_pg", "10", ceil ( $numofpages ), $page ); ?>
		 </p>
		
		<!-- paging -->
    </div>
    <div class="corner-round-01-bottom-right">
        <div class="corner-round-01-bottom-left">

            <div class="corner-round-01-bottom-bg"></div>
        </div>
    </div>   
</div>   
<!-- } Paging -->

<!-- } Product List -->

                     
        </div>  
    </div>
    <div style="clear:both;"></div>      
    <!-- } Main Page-Content -->  
    
            </div>